import sys

from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton, QVBoxLayout, QLabel

class AnotherWindow(QWidget):
    def __init__(self):
        super().__init__()

        label = QLabel("This is another window")
        layout = QVBoxLayout()
        layout.addWidget(label)
        self.setLayout(layout)

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My App")
        self.w = AnotherWindow()
        button = QPushButton("Click me")
        button.clicked.connect(self.toggle_window)

        self.setCentralWidget(button)

    def toggle_window(self, checked):
        if self.w.isVisible():
            self.w.hide()
        else:
            self.w.show()

app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
